//
//  CATakeMoneyView.m
//  LNH
//
//  Created by twentylx on 2018/1/23.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CATakeMoneyView.h"

@implementation CATakeMoneyView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {

}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self setNeedsUpdateConstraints];
    
    [self addSubview:self.bankView];
    [self.bankView addSubview:self.titleLabel];
    [self.bankView addSubview:self.bankIconImageView];
    [self.bankView addSubview:self.bankTitleLabel];
    [self.bankView addSubview:self.bankNoLabel];
    [self.bankView addSubview:self.moreImageView];
    
    [self addSubview:self.moneyView];
    [self.moneyView addSubview:self.moneyTitleLabel];
    [self.moneyView addSubview:self.moneyIconLabel];
    [self.moneyView addSubview:self.moneyTextField];
    [self.moneyView addSubview:self.lineView];
    [self.moneyView addSubview:self.moneyLabel];
    
    [self addSubview:self.submitButton];
}

#pragma mark layout
- (void) updateConstraints {
    [super updateConstraints];
    
    [_bankView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self).offset(50);
        make.height.mas_equalTo(60);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankView).offset(20);
        make.centerY.equalTo(self.bankView);
    }];
    
    [_bankIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankView).offset(20);
        make.centerY.equalTo(self.bankView);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
    
    [_bankTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankIconImageView.mas_right).offset(20);
        make.top.equalTo(self.bankView).offset(10);
    }];
    
    [_bankNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankTitleLabel);
        make.top.equalTo(self.bankTitleLabel.mas_bottom).offset(5);
    }];
    
    [_moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bankView).offset(-30);
        make.centerY.equalTo(self.bankView);
    }];
    
    [_moneyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.bankView.mas_bottom).offset(50);
        make.height.mas_equalTo(125);
    }];
    
    [_moneyTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.moneyView).offset(20);
        make.top.equalTo(self.moneyView).offset(20);
    }];
    
    [_moneyIconLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.moneyView).offset(20);
        make.top.equalTo(self.moneyTitleLabel.mas_bottom).offset(10);
        make.width.mas_offset(60);
        make.height.mas_offset(40);
    }];
    
    [_moneyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.moneyIconLabel.mas_right).offset(5);
        make.centerY.equalTo(self.moneyIconLabel);
        make.right.equalTo(self.moneyView);
        make.height.mas_equalTo(40);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.moneyView);
        make.top.equalTo(self.moneyTextField.mas_bottom);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.moneyTitleLabel);
        make.top.equalTo(self.lineView.mas_bottom).offset(10);
    }];
    
    [_submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(40);
        make.top.equalTo(self.moneyView.mas_bottom).offset(50);
        make.right.equalTo(self).offset(-40);
        make.height.mas_equalTo(40);
    }];
}

#pragma mark get & set
- (UIView *)bankView {
    if (!_bankView) {
        _bankView = [UIView new];
        _bankView.backgroundColor = [UIColor whiteColor];
    }
    return _bankView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel.text =  @"请选择银行卡";
        _titleLabel.font = [UIFont systemFontOfSize:20];
    }
    return _titleLabel;
}

- (UIImageView *)bankIconImageView {
    if (!_bankIconImageView) {
        _bankIconImageView = [UIImageView new];
        _bankIconImageView.image = LMImageNamed(@"category");
        _bankIconImageView.hidden = YES;
    }
    return _bankIconImageView;
}

- (UILabel *)bankTitleLabel {
    if (!_bankTitleLabel) {
        _bankTitleLabel = [UILabel new];
        _bankTitleLabel.text =  @"中国工商银行";
        _bankTitleLabel.font = [UIFont systemFontOfSize:14];
        _bankTitleLabel.hidden = YES;
    }
    return _bankTitleLabel;
}

- (UILabel *)bankNoLabel {
    if (!_bankNoLabel) {
        _bankNoLabel = [UILabel new];
        _bankNoLabel.text =  @"尾号1247储蓄卡";
        _bankNoLabel.textColor = RGBCOLOR(113, 113, 113);
        _bankNoLabel.font = [UIFont systemFontOfSize:14];
        _bankNoLabel.hidden = YES;
    }
    return _bankNoLabel;
}

- (UIImageView *)moreImageView {
    if (!_moreImageView) {
        _moreImageView = [UIImageView new];
        _moreImageView.image = LMImageNamed(@"more");
    }
    return _moreImageView;
}

- (UIView *)moneyView {
    if (!_moneyView) {
        _moneyView = [UIView new];
        _moneyView.backgroundColor = [UIColor whiteColor];
    }
    return _moneyView;
}

- (UILabel *)moneyTitleLabel {
    if (!_moneyTitleLabel) {
        _moneyTitleLabel = [UILabel new];
        _moneyTitleLabel.text = @"提现金额";
        _moneyTitleLabel.font = [UIFont systemFontOfSize:20];
    }
    return _moneyTitleLabel;
}

- (UILabel *)moneyIconLabel {
    if (!_moneyIconLabel) {
        _moneyIconLabel = [UILabel new];
        _moneyIconLabel.text = @"￥：";
        _moneyIconLabel.font = [UIFont systemFontOfSize:25 weight:1];
    }
    return _moneyIconLabel;
}

- (UITextField *)moneyTextField {
    if (!_moneyTextField) {
        _moneyTextField = [UITextField new];
        _moneyTextField.font = [UIFont systemFontOfSize:25 weight:1];
        _moneyTextField.placeholder = @"请输入金额";
        _moneyTextField.keyboardType = UIKeyboardTypeNumberPad;
    }
    return _moneyTextField;
}

- (UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(171, 171, 171);
    }
    return _lineView;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [UILabel new];
        _moneyLabel.text = @"可用余额：0.00";
        _moneyLabel.textColor = RGBCOLOR(171, 171, 171);
        _moneyLabel.font = [UIFont systemFontOfSize:12];
    }
    return _moneyLabel;
}

- (UIButton *)submitButton {
    if (!_submitButton) {
        _submitButton = [UIButton new];
        [_submitButton setTitle:@"提现" forState:UIControlStateNormal];
        _submitButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_submitButton setBackgroundColor:RGBCOLOR(255, 61, 0)];
        _submitButton.layer.cornerRadius = 5;
    }
    return _submitButton;
}

@end
